<?php


namespace App\Http\Controllers\Api;


use App\Services\GoodsImportService;
use App\Services\GoodsImportEditService;
use Illuminate\Http\Request;
use App\Utils\Code;

class GoodsImportController extends BaseController
{
    public function import(Request $request, GoodsImportService $service) {
        if (!$file = $request->file('file')) {
            throw new \Exception('没有上传任何文件', Code::PARAMETER_ERROR);
        }
        return $service->importGoods($file, $request->input());
    }
    
    public function filePaginate(Request $request, GoodsImportService $service) {
        return $service->filePaginate($request->query());
    }
    
    public function errorPaginate(Request $request, GoodsImportService $service) {
        return $service->errorPaginate($request->query());
    }
    
    public function importEdit(Request $request, GoodsImportEditService $service) {
        if (!$file = $request->file('file')) {
            throw new \Exception('没有上传任何文件', Code::PARAMETER_ERROR);
        }
        return $service->importEdit($file, $request->input());
    }
    
    public function editFilePaginate(Request $request, GoodsImportEditService $service) {
        return $service->filePaginate($request->query());
    }
    
    public function editErrorPaginate(Request $request, GoodsImportEditService $service) {
        return $service->errorPaginate($request->query());
    }
}
